import java.util.Scanner;

public class Solution {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            int len1 = sc.nextInt();
            int len2 = sc.nextInt();
            sc.nextLine();
            int[][] nums= new int[len1][len2];
            for (int i = 0; i < len1; i++) {
                String[] s = sc.nextLine().trim().split(" ");
                for (int j = 0; j < len2; j++) {
                    nums[i][j] = Integer.parseInt(s[j]);
                }

            }
            System.out.println(maximalSquare(nums));
        }
    }
    public static int maximalSquare(int[][] matrix) {
        int len1 = matrix.length, len2 = matrix[0].length;
        int[][] dp = new int[len1+1][len2+1];
        for (int i = 1; i < len1+1; i++) {
            for (int j = 1; j < len2 + 1; j++) {
                if (matrix[i-1][j-1] == 0) {
                    dp[i][j] = Math.max(Math.max(dp[i-1][j-1], dp[i-1][j]), dp[i][j-1]);
                }else {
                    dp[i][j] = Math.min(Math.min(dp[i-1][j-1], dp[i-1][j]), dp[i][j-1]) + 1;
                }
            }
        }
        return dp[len1][len2] * dp[len1][len2];
    }

}


/*
* 上面的解答是错的
* 状态转移方程弄错了准确点说是状态弄错了，把dp（X）（y）看作为当前小格为右下顶点的区域中的最大正方形的边长
*  实际状态应该是：dp（X）（y）表示以当前小格作为右下角顶点的所求最大正方形边长
* 选状态特别重要：自变量往往是所求目标的末尾或者右下顶点，不是整个需要求的串或者整个区域*/

class Solution2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            int len1 = sc.nextInt();
            int len2 = sc.nextInt();
            sc.nextLine();
            int[][] nums= new int[len1][len2];
            for (int i = 0; i < len1; i++) {
                String[] s = sc.nextLine().trim().split(" ");
                for (int j = 0; j < len2; j++) {
                    nums[i][j] = Integer.parseInt(s[j]);
                }

            }
            System.out.println(maximalSquare(nums));
        }
    }
    public static int maximalSquare(int[][] matrix) {
        int len1 = matrix.length, len2 = matrix[0].length;
        int[][] dp = new int[len1+1][len2+1];
        int res = 0;
        for (int i = 1; i < len1+1; i++) {
            for (int j = 1; j < len2 + 1; j++) {
                if (matrix[i-1][j-1] == 1) {

                    dp[i][j] = Math.min(Math.min(dp[i - 1][j - 1], dp[i - 1][j]), dp[i][j - 1]) + 1;
                    if (dp[i][j] > res) {
                        res = dp[i][j];
                    }
                }
            }
        }
        return res * res;
    }

}
